from typing import List
# 会漏
class Solution:
    def threeSum(self, nums: List[int]) -> List[List[int]]:
        length = len(nums)
        if length < 3:
            return []

        nums.sort()
        minv, maxv = nums[0], nums[-1]
        result = set()
        i, j = 0, 1
        vi, vj = nums[i], nums[j]
        while j < length - 1 and i < j:
            if vi + vj + minv < 0:
                diff = 0 - vi - vj
                includeDiff = self.search(nums, diff, i, j)
                if includeDiff:
                    item = sorted([vi, vj, diff])
                    result.add(tuple(item))
            elif vi + vj + minv == 0:
                item = sorted([vi, vj, minv])
                result.add(tuple(item))
            else:
                break
            if i < j - 1:
                i += 1
            else:
                j += 1
            vi, vj = nums[i], nums[j]
        return [list(t) for t in result]

    def search(self, nums: list, v: int, i1: int, i2: int):
        try:
            nums.index(v, 0, i1)
            return True
        except ValueError:
            try:
                nums.index(v, i1 + 1, i2)
                return True
            except ValueError:
                try:
                    nums.index(v, i2 + 1)
                    return True
                except ValueError:
                    return False

solu = Solution()
# print(solu.threeSum([-1, 0, 1, 2, -1, -4]))
print(solu.threeSum([0, 0, 0]))      